"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.field = void 0;

var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));

var _react = require("react");

var _jsxRuntime = require("react/jsx-runtime");

var _proUtils = require("@ant-design/pro-utils");

var _omit = _interopRequireDefault(require("omit.js"));

var _Field = _interopRequireDefault(require("../../Field"));

var field = function field(item, _ref) {
  var action = _ref.action,
      formRef = _ref.formRef,
      type = _ref.type,
      originItem = _ref.originItem;

  /** 公用的 类型 props */
  var formFieldProps = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, (0, _omit.default)(item, ['dataIndex', 'width', 'render', 'renderFormItem', 'renderText', 'title'])), {}, {
    name: item.dataIndex,
    width: item.width,
    render: (item === null || item === void 0 ? void 0 : item.render) ? function (dom, entity, renderIndex) {
      var _item$render, _item$getFormItemProp, _item$getFieldProps;

      return item === null || item === void 0 ? void 0 : (_item$render = item.render) === null || _item$render === void 0 ? void 0 : _item$render.call(item, dom, entity, renderIndex, action === null || action === void 0 ? void 0 : action.current, (0, _objectSpread2.default)((0, _objectSpread2.default)({
        type: type
      }, item), {}, {
        formItemProps: (_item$getFormItemProp = item.getFormItemProps) === null || _item$getFormItemProp === void 0 ? void 0 : _item$getFormItemProp.call(item),
        fieldProps: (_item$getFieldProps = item.getFieldProps) === null || _item$getFieldProps === void 0 ? void 0 : _item$getFieldProps.call(item)
      }));
    } : undefined
  });

  var defaultRender = function defaultRender() {
    return (0, _jsxRuntime.jsx)(_Field.default, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, formFieldProps), {}, {
      ignoreFormItem: true
    }));
  };

  var renderFormItem = (item === null || item === void 0 ? void 0 : item.renderFormItem) ? function (_, config) {
    var _item$renderFormItem, _item$getFormItemProp2, _item$getFieldProps2;

    var renderConfig = (0, _proUtils.omitUndefined)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, config), {}, {
      onChange: undefined
    }));
    return item === null || item === void 0 ? void 0 : (_item$renderFormItem = item.renderFormItem) === null || _item$renderFormItem === void 0 ? void 0 : _item$renderFormItem.call(item, (0, _objectSpread2.default)((0, _objectSpread2.default)({
      type: type
    }, item), {}, {
      formItemProps: (_item$getFormItemProp2 = item.getFormItemProps) === null || _item$getFormItemProp2 === void 0 ? void 0 : _item$getFormItemProp2.call(item),
      fieldProps: (_item$getFieldProps2 = item.getFieldProps) === null || _item$getFieldProps2 === void 0 ? void 0 : _item$getFieldProps2.call(item),
      originProps: originItem
    }), (0, _objectSpread2.default)((0, _objectSpread2.default)({}, renderConfig), {}, {
      defaultRender: defaultRender,
      type: type
    }), formRef.current);
  } : undefined;

  if (item === null || item === void 0 ? void 0 : item.renderFormItem) {
    var dom = renderFormItem === null || renderFormItem === void 0 ? void 0 : renderFormItem(null, {});
    if (!dom || item.ignoreFormItem) return dom;
  }

  return /*#__PURE__*/(0, _react.createElement)(_Field.default, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, formFieldProps), {}, {
    key: "".concat(item.key, "-").concat(item.index),
    renderFormItem: renderFormItem
  }));
};

exports.field = field;